/*
 ============================================================================
 Name		: P2PMessage.h
 Author	  : 
 Version	 : 1.0
 Copyright   : 
 Description : CP2PMessage declaration
 ============================================================================
 */

#ifndef P2PMESSAGE_H
#define P2PMESSAGE_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

// CLASS DECLARATION

/**
 *  CP2PMessage
 * 
 */
class CP2PMessage : public CBase
	{
public:
	enum TType
		{
		EMessageToSend,
		EResponseToSend,
		EMessageSent,
		EResponseSent,
		EMessageReceived,
		EResponseReceived
		};
	
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CP2PMessage();

	/**
	 * Two-phased constructor.
	 */
	static CP2PMessage* NewL(TType aType,
			const TDesC8& aAppId,
			const TDesC8& aMessageId,
			const TDesC8& aContent,
			const TTime& aValidUntil);

	/**
	 * Two-phased constructor.
	 */
	static CP2PMessage* NewLC(TType aType,
			const TDesC8& aAppId,
			const TDesC8& aMessageId,
			const TDesC8& aContent,
			const TTime& aValidUntil);
	
	const TDesC8& AppId() const;
	
	const TDesC8& MessageId() const;
	
	const TDesC8& Content() const;
	
	const TTime& ValidUntil() const;

	TBool IsValid() const;
	
	static TInt ResponseMapOrder(const CP2PMessage& aA, const CP2PMessage& aB);

	HBufC8* SerializeL();
	
	HBufC8* ToJSON();
	
	static CP2PMessage* FromSerializedLC(const TDesC8& serialized);
	
	TType Type() const;
	
	void SetType(TType aType);
private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CP2PMessage(TType aType);

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL(const TDesC8& aAppId,
			const TDesC8& aMessageId,
			const TDesC8& aContent,
			const TTime& aValidUntil);
	
	TType iType;
	RBuf8 iAppId;
	RBuf8 iMessageId;
	RBuf8 iContent;
	TTime iValidUntil;

	};

#endif // P2PMESSAGE_H
